package com.yuanli.cosmeticmirror.view.adapter;

import android.graphics.Color;
import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.yuanli.cosmeticmirror.R;
import com.yuanli.cosmeticmirror.base.MyApp;
import com.yuanli.cosmeticmirror.bean.PhotoFrameBean;
import com.yuanli.cosmeticmirror.widget.FilterImageView;

import org.jetbrains.annotations.NotNull;

import comenjoy.com.imageloadlibrary.GlideUtil;

public class PhotoFrameAdapter extends BaseQuickAdapter<PhotoFrameBean, BaseViewHolder> {


    private int position = -1;

    public PhotoFrameAdapter() {
        super(R.layout.items_filter);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, PhotoFrameBean photoFrameBean) {
        FilterImageView imageView = baseViewHolder.getView(R.id.filter_img);
        GlideUtil.getInstance().loadImage(MyApp.getInstance(), photoFrameBean.getImgUrl(), imageView);
        imageView.setCheck(position == baseViewHolder.getAdapterPosition());
        photoFrameBean.setCheck(position == baseViewHolder.getAdapterPosition());
        if (!MyApp.IsVIP) {
            imageView.setZheZhao(!TextUtils.equals(photoFrameBean.getIsvip(), "1"));
        }
    }

    public void setPosition(int position) {
        if (position == this.position) {
            this.position = -1;
        } else {
            this.position = position;
        }
        notifyItemRangeChanged(0, getItemCount());
    }
}
